package bing.designpattern.builder;

public class BuilderExample {

	private final int servingSize;
	private final int servings;
	private final int calorgies;
	private final int fat;
	private final int sodium;
	private final int carbohydrate;
	
	private BuilderExample(Builder builder){
		this.servingSize=builder.servingSize;
		this.servings=builder.servings;
		this.calorgies=builder.calorgies;
		this.fat=builder.sodium;
		this.sodium=builder.sodium;
		this.carbohydrate=builder.carbohydrate;
	}
	
	public static class Builder{
		//required 
		private final int servingSize;
		private final int servings;
		//optional
		private int calorgies=0;
		private int fat=0;
		private int sodium=0;
		private int carbohydrate=0;
		
		public Builder(int servingSize,int servings){
			this.servings=servings;
			this.servingSize=servingSize;
		}
		
		public Builder setCalorgies(int calorgies){
			this.calorgies=calorgies;
			return this;
		}
		
		public Builder setFat(int fat){
			this.fat=fat;
			return this;
		}
		
		public Builder setSodium(int sodium){
			this.sodium=sodium;
			return this;
		}
		
		public Builder setCarbohydrate(int carbohydrate){
			this.carbohydrate=carbohydrate;
			return this;
		}
		
		public BuilderExample build(){
			return new BuilderExample(this);
		}
	}
}
